package cn.edu.scau.cmi.xiaozhenlin.abstractFactoryMethod;

import cn.edu.scau.cmi.xiaozhenlin.abstractFactoryMethod.factory.AbstractFactory;
import cn.edu.scau.cmi.xiaozhenlin.abstractFactoryMethod.factory.piccFactory;
import cn.edu.scau.cmi.xiaozhenlin.abstractFactoryMethod.factory.pingAnFactory;
import cn.edu.scau.cmi.xiaozhenlin.insurance.Insurance;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.TextArea;
import javafx.scene.image.ImageView;

public class AbstractFactoryController {

	@FXML
	private ImageView img;

	@FXML
	private ChoiceBox<String> sp_what;

	@FXML
	private TextArea tv_showMsg;

	public void Init() {
		// TODO Auto-generated method stub
		ObservableList<String> options = FXCollections.observableArrayList("PICC_身体受伤", "PICC_汽车损坏", "PICC_汽车刮伤",
				"PingAn_身体受伤", "PingAn_汽车损坏", "PingAn_汽车刮伤");
		System.out.println(options);
		this.sp_what.setItems(options);
		// this.sp_what.getSelectionModel().select(0);
		sp_what.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() {
			@Override
			public void changed(ObservableValue<? extends Number> arg0, Number arg1, Number arg2) {
				// TODO 自动生成的方法存根
				sp_what.getSelectionModel().select(arg2.intValue());
				String select = sp_what.getValue();
				AbstractFactory factory = null;
				if (select.contains("PICC")) {
					factory = new piccFactory();
				} else {
					factory = new pingAnFactory();
				}
				Insurance insurance;
				if (select.contains("身体受伤")) {
					insurance = factory.getPhysicalIujury();
				} else if (select.contains("汽车损坏")) {
					insurance = factory.getCarDamage();
				} else {
					insurance = factory.getScratch();
				}
				tv_showMsg.clear();
				System.out.println(sp_what.getValue());
				tv_showMsg.setText(insurance.claim());
			}

		});
	}

}
